using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using emp.ProcessFlow;
using emp.BLL;
using emp.Model;

public partial class crm_quest_RelateQsOptionAnswerCreate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            if(Request["pid"]!=null){
                p_qsd_id.Value=Request["pid"].ToString();
                c_qsd_id.Value = Request["cid"].ToString();
                qrs_uid.Value = Request["qsruid"].ToString();
                Quest quest = new Quest();
                int qsd_id = Convert.ToInt32(Request["pid"].ToString());
                int cqsd_id = Convert.ToInt32(Request["cid"].ToString());
                QuestInfo qstInfo = quest.getQuestInfo(qsd_id);
                this.p_qsd_name.Text = qstInfo.QSD_NAME;

                DataSet ds = quest.getRelateQuestLintOB(qsd_id);
                if (ds != null)
                {
                    select_tem.DataSource = ds;
                    select_tem.DataTextField = "qsd_name";
                    select_tem.DataValueField = "qsd_uid";
                    select_tem.DataBind();                        
                    ds.Dispose();

                }
                select_tem.SelectedValue = c_qsd_id.Value;
                select_tem.Enabled = false;
                DataSet data1 = quest.getRelateOption(qsd_id);
                if (data1 != null)
                {
                    p_option_aws.DataSource = data1;
                    p_option_aws.DataTextField = "qsa_answer_name";
                    p_option_aws.DataValueField = "qsa_uid";
                    p_option_aws.DataBind();
                    data1.Dispose();
                }
                DataSet data2 = quest.getRelateOption(cqsd_id);
                if (data2 != null)
                {
                    c_option_aws.DataSource = data2;
                    c_option_aws.DataTextField = "qsa_answer_name";
                    c_option_aws.DataValueField = "qsa_uid";
                    c_option_aws.DataBind();
                    data2.Dispose();
                }
            }
        }
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        int pid = Convert.ToInt32(p_qsd_id.Value);
        int cid = Convert.ToInt32(c_qsd_id.Value);

        int paswid = Convert.ToInt32(p_option_aws.SelectedValue);
        int caswid = Convert.ToInt32(c_option_aws.SelectedValue);
        Quest quest = new Quest();
        int id = quest.getRelateQuestId(pid, cid);
        if (!quest.IsExistRelateOption(id, paswid, caswid))
        {
            quest.InsertRelateOption(id, paswid, caswid);
        }

        Response.Redirect("RelateQstOptionCreate.aspx?pid=" + pid + "&cid=" + cid + "&qsruid=" + qrs_uid.Value);
    }
}
